﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Shcool.Models;

namespace GameShcool.Models
{

    public class MainRepository
    {
        UserContext db = new UserContext ( );


        public IQueryable<Course> Courses ( )
        {
            return db.Courses;
        }

        public IQueryable<Course> Courses (int id )
        {
            var S = ( from st in db.Courses
                      where st.CourseID == id
                      select st ).SingleOrDefault ( );
            if ( S != null )
            {
                return db.Courses;
            }
            return db.Courses;
        }


        public IQueryable<Student> Students ( int id )
        {
            var S = ( from st in db.Students
                      where st.StudentID == id
                      select st ).SingleOrDefault ( );
            if ( S != null )
            {
                return db.Students;
            }
            return db.Students;
        }
        /// <summary>
        /// Updates a single news item. Will not notify anyone AT ALL if this somehow fails,
        /// for instance if the given news item cannot be found. Maybe it should.
        /// </summary>
        /// <param name="newsItem"></param>
        /*      public void UpdateNewsItem ( NewsItem newsItem )
              {
                  NewsItem oldItem = db.NewsItems.Where ( x => x.ID == newsItem.ID ).SingleOrDefault ( );
                  if ( oldItem != null )
                  {
                      oldItem.Title = newsItem.Title;
                      oldItem.NewsText = newsItem.NewsText;
                      oldItem.Category = newsItem.Category;
                  }
              }

              /// <summary>
              /// Saves any changes which might have been made to the data store.
              /// </summary>
              public void Save ( )
              {
                  db.SubmitChanges ( );
              }
         *  */
    }
}